home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 018a / amac41.zip / RFR005.QM < prev    next >
Text File  |  1991-08-26  |  16KB  |  339 lines

  1. *                               RFR005.QM
  2. *                        Written By Tom Hogshead
  3. *                       [ See RFRMxx.QM For Use ]
  4. *                                8/23/91
  5. *  Key       Subfile                       Description
  6. * =====  ===============  ====================================================
  7. * @(0)                    Count Words in a File
  8. * @(3)                    Alternate version of @0 by John Goodman
  9. * @(1)                    Count Characters in a Block
  10. * @(2)                    Count Characters in a File
  11. * @(4)                    Count Words in a Block by John Goodman
  12. *
  13. *          {e:\up\RFRM*}--Return To RFRMxx.QM
  14. * (Calibrated) Test File
  15. *
  16. *-- eoi
  17.  
  18.  
  19. * 
  20. * --------------------------------------
  21. * @(0) Macro To Count Words In File
  22. * --------------------------------------
  23. * This macro counts the number of words in a File.  A word is
  24. * defined as a string of characters contained in either the
  25. * DefaultWordSet or AltWordSet separated by a word delimiter.  The
  26. * number of words in the File equal the number of lines in the NUL
  27. * file after execution.
  28.  
  29. * @0 differs from @9 in that @9 considers a "word" to be at least one
  30. * letter or number separated by a space or the following word
  31. * separators: !@#$%^&*'()+|-=\,./;'[]<>?:"{} ...  @9 counts words like
  32. * "can't" as two words; @0 counts them as one word.
  33.  
  34. * Test macro using the calibrated file WORD (41 words).
  35.  
  36. * [ Number of WORDS in File ] = [ Number of LINES in temp file ]
  37.  
  38. @0 Macrobegin
  39.         AltWordSet
  40.         UnMarkBlock
  41.         EndLine
  42.         Dropanchor
  43.         StoreScrBuff "c" Return
  44.         BegFile
  45.     LOOP:
  46.         MarkWord
  47.     jfalse 1:
  48.         AppendScrBuff "c" Return
  49.     1:  WordRight
  50.     jtrue LOOP:
  51.         EditFile "NUL" Return Quit
  52.         EditFile Return
  53.         GetScrBuff "c" Return
  54.         UnMarkBlock
  55.         DefaultWordSet
  56.         BegFile
  57.         DelLine
  58.         EndFile
  59. *
  60. * 82 bytes Wed  02-20-1991  16:54:02
  61. * 83 bytes Mon  07-15-1991  11:06:17 (TH @0, changed ! to NUL)
  62. * 45 bytes Wed  08-21-1991  23:55:04 (TH @0)
  63.  
  64.  
  65.  
  66. * 
  67. * ----------------------------------------------------------------------
  68. * @(1) Count Number Of Characters In A Block
  69. * ----------------------------------------------------------------------
  70. * To: Mike Butler, RelayNet, May 4, 1991  15:16:09
  71. * MB> Is there any way to create a macro to count the number of
  72. * MB> characters in a block?
  73.  
  74. * This QEdit macro determines a block's byte size and provides a means
  75. * to calculate the Number of Characters in a block.  Block Byte Size can
  76. * be useful for uploading CompuServe files where upload file descriptions
  77. * are limited to 465 bytes:
  78. *     Block Byte Size = Size of block if it were a file
  79. *     Character Count = (Block Byte Size) minus 2 x (Number of Lines)
  80. * Mark a block.  Block need not be closed.  Block byte size will be shown in
  81. * a window and in front of the last line of a copy of the block.  Press
  82. * <enter> to remove the window from the screen and return to the our
  83. * starting point.  To determine the number of actual characters in a block,
  84. * including spaces between text, subtract 2 x (number of lines in window)
  85. * from (byte size).  The paragraph below with asterisks is 274 bytes, and
  86. * has 274 - 4 x 2 = 266 characters including spaces.
  87.  
  88. * NOTE: c:temp and c:dir are temporary files created and deleted from the
  89. * disk.  Rename files and run QMAC if this causes problems.  This macro has
  90. * only been tested with DOS 3.3.  SaveFile is used rather than WriteBlock
  91. * in case c:temp and c:dir exist before running.
  92.  
  93. @1 Macrobegin
  94.         Editfile "c:temp" Return        * Load temp file
  95.         killfile Quit                   * Kill/quit c:temp
  96.         EditFile Return                 * Load empty c:temp
  97.         Copyblock                       * Copy block to temp file
  98.         EndFile DelLine                 * Delete extra blank line
  99.         Savefile                        * Save temp file to get size
  100.         DOS "Dir " Currentfilename      * Get  DIR list of c:temp
  101.         ">C:dir" Return Return          * Save DIR list of c:temp
  102.         Editfile "C:dir" Return         * Load DIR list
  103.         Gotoline "5" Return             * CursorDown to c:temp line
  104.         Wordright Markword Copy         * Copy size to scrap
  105.         Killfile Quit                   * Kill/quit c:dir
  106.         Editfile "c:temp" Return        * Load c:temp
  107.         Killfile                        * Kill it
  108.         Endfile Begline                 *
  109.         "Block size=" Paste             * Paste block size at bottom
  110.         Makebotofscreen                 * Re-position
  111.         Pause                           * Press <enter> to remove block size
  112.         Quit                            * Character Count = Block Size
  113.                                         *     minus 2 x Number of Lines
  114. * 114 bytes Sat  05-04-1991  15:15:25
  115.  
  116. * The following macro counts the number of characters in a File.  After
  117. * running, the byte size of the File *without* spaces is shown in
  118. * column 1 on the last line.  Subtract 2 x number of lines from the byte
  119. * size to get the number of actual characters in the File.
  120.  
  121. * 
  122. * ----------------------------------------------------------------------
  123. * @(2) Count Number Of Characters In A File
  124. * ----------------------------------------------------------------------
  125.  
  126. @2 Macrobegin
  127.         UnMarkBlock                     * Un-mark all blocks
  128.         BegFile Markblockbegin          * Mark File
  129.         EndFile Markblockend            *
  130.         Editfile "c:temp" Return        * Load empty c:temp
  131.         Killfile Quit                   * Kill/quit c:temp
  132.         Editfile Return                 * Load empty temp file
  133.         Copyblock Unmarkblock           * Copy File to temp file
  134.         Findreplace " " Return          * Replace all single spaces
  135.         DelLine Return "GN" Return      * With Blanks, globally
  136.  DELBLANKLINES:                         *
  137.         Begfile                         * Get to begin of file
  138.  CHK4BLANK:                             *
  139.         Endline Begline                 * Check if line has text
  140.         Jtrue  NOTBLANK:                * If so, go to NOTBLANK
  141.         Delline                         * Or line is blank, delete it
  142.         Jtrue CHK4BLANK:                * Go check next line
  143.  NOTBLANK:                              *
  144.         Endpara                         *ELSE  Move to paragraph end
  145.         Cursordown                      * Move down to next line
  146.         Jtrue CHK4BLANK:                * If not eof, check again
  147.  GETCOUNT:                              *
  148.         Savefile                        * Save temp file to get size
  149.         DOS "DIR " Currentfilename      * Get  DIR list of c:temp
  150.         ">C:dir" Return Return          * Save DIR list of c:dir
  151.         Editfile "C:dir" Return         * Load DIR list
  152.         Gotoline "5" Return             * Cursordown to c:temp line
  153.         Wordright Markword Copy         * Copy size to scrap
  154.         Killfile Quit                   * Kill/quit c:dir
  155.         Editfile  "c:temp" Return       * Load compressed c:temp
  156.         Killfile                        * Kill c:temp disk copy
  157.         Begline "Byte size=" Paste      * Paste byte size at bottom
  158.         Makebotofscreen                 * Re-position
  159.         Pause                           * Press <enter> to remove window
  160.         Quit                            * Character Count = Byte Size
  161.                                         *     minus 2 x Number of Lines
  162. * 92 bytes Wed  02-20-1991  17:02:29
  163. * 141 bytes Sat  05-04-1991  15:38:07 changed temp file names, added pause
  164. *                                     corrected gotoline "5"
  165.  
  166. * 
  167. * ---------------------------------------------
  168. * @(3) Count Words in File
  169. *      Alternate version of @0 by John Goodman
  170. * ---------------------------------------------
  171. * This macro will count the number of words in the current file.  A
  172. * word is considered to be a sequence of one or more characters in
  173. * the AltWordSet delimited by at least one character that is not in
  174. * the AltWordSet (this definition should suffice for most
  175. * applications).  The number of words in the file is displayed in a
  176. * separate window after they have been counted.  When the Enter key
  177. * is pressed, the word count display will be removed and the cursor
  178. * will be positioned at the top of the original file. The macro
  179. * should work consistently regardless of mode toggle or QConfig
  180. * settings and will not change the edit status of the original
  181. * file.  The macro does, however, set the word character set to
  182. * DefaultWordSet at the end of the macro.
  183. *
  184. @3  MacroBegin
  185.     AltWordSet          * Use alternate word character set
  186.     UnmarkBlock BegFile * Remove blocks and start at top
  187.     OneWindow           * Remove any windows
  188.     EditFile            * Use the NUL file for counting
  189.       "NUL" Return
  190.     Quit                * Make sure NUL file is empty
  191.     HorizontalWindow    * Create window for counting
  192.     EditFile Return     * Re-edit the NUL file
  193.     DropAnchor          * Start a block
  194.     "0123456789"        * Type digits 0-9
  195.     Copy BegLine        * Make six copies of digits line
  196.     Paste 6
  197.     MarkCharacter       * Copy the digits w/out EOL char
  198.     EndLine Copy
  199.     UnmarkBlock
  200.     PrevWindow          * Return to original file
  201.  MAINLOOP:              * Loop for each word in file
  202.     MarkWord            * Test if a word at cursor position
  203.     JFalse NEXTWORD:    * If not, skip to next word
  204.     NextWindow          * Go to counting window
  205.     EndFile BegLine     * Go to ones digit position
  206.  INCRLOOP:
  207.     DelCh               * Delete (increment) the current digit
  208.     EndLine             * Test if any digits remaining
  209.  JTrue INCRDONE:
  210.     Paste               * Re-paste the 0-9 string
  211.     UnmarkBlock
  212.     CursorUp            * Go to up next significant digit
  213.  Jump INCRLOOP:         * Increment next significant digit
  214.  INCRDONE:
  215.     PrevWindow          * Return to original file
  216.  NEXTWORD:
  217.     WordRight           * Go to next word right
  218.  JTrue MAINLOOP:        * If no words to right, display count
  219.     BegFile             * Return to beginning of original file
  220.     NextWindow          * Go to count window
  221.     BegFile CursorRight * Go to top of 2nd column
  222.     MarkColumn          * Delete all but column 1
  223.     EndLine PageDown
  224.     DeleteBlock
  225.     JOINLOOP:           * Join column 1 into a single line
  226.       CursorUp
  227.       JFalse PROMPT:
  228.       JoinLine
  229.     Jump JOINLOOP:
  230.  PROMPT:
  231.     EndLine             * Go to end of count and display prompt
  232.     " Words... Press <Enter> to Continue"
  233.     Pause               * Wait for user to press Enter
  234.     Quit CloseWindow    * Delete the NUL file and close window
  235.     DefaultWordSet      * Reset default word set characters
  236. *
  237. * 167 bytes Fri  08-23-1991  21:29:35 (JG @3)
  238.  
  239. * 
  240. * ---------------------------------
  241. * @(4) Count Words in Marked Block
  242. * ---------------------------------
  243. * This macro will count the number of words in the currently marked
  244. * block. Any type of block may be used and both block end points
  245. * need not be set. A word is considered to be a sequence of one or
  246. * more characters in the AltWordSet delimited by at least one
  247. * character that is not in the AltWordSet (this definition should
  248. * suffice for most applications).  The number of words in the block
  249. * is displayed in a separate window after they have been counted.
  250. * When the Enter key is pressed, the word count display will be
  251. * removed and the cursor will be positioned at its original
  252. * location in the file (the original block will be unmarked). The
  253. * macro should work consistently regardless of mode toggle or
  254. * QConfig settings and will not change the edit status of the
  255. * original file.  The macro does, however, set the word character
  256. * set to DefaultWordSet at the end of the macro.
  257. *
  258. @4  MacroBegin
  259.     AltWordSet          * Use alternate word character set
  260.     OneWindow           * Remove any windows
  261.     EditFile            * Use the NUL file for counting
  262.       "NUL" Return
  263.     Quit                * Make sure NUL file is empty
  264.     HorizontalWindow    * Create window for counting
  265.     EditFile Return     * Re-edit the NUL file
  266.     CopyBlock           * Copy the block of text to NUL file
  267.     JFalse END:         * If no block, exit
  268.     UnmarkBlock         * Unmark the block
  269.     SplitLine           * Put blank line at top
  270.     DropAnchor          * Start a block
  271.     "0123456789"        * Type digits 0-9
  272.     Copy BegLine        * Make six copies of digits line
  273.     Paste 6
  274.     MarkCharacter       * Copy the digits w/out EOL char
  275.     EndLine Copy
  276.     UnmarkBlock
  277.     BegFile             * Go to beginning of text
  278.     CursorDown 7
  279.  MAINLOOP:              * Loop for each word in file
  280.     DeleteBlock         * Delete the last word processed
  281.     MarkWord            * Test if a word at cursor position
  282.     JFalse NEXTWORD:    * If not, skip to next word
  283.     CursorUp BegLine    * Go to ones digit position
  284.  INCRLOOP:
  285.     DelCh               * Delete (increment) the current digit
  286.     EndLine             * Test if any digits remaining
  287.  JTrue INCRDONE:
  288.     Paste               * Re-paste the 0-9 string
  289.     UnmarkBlock
  290.     CursorUp            * Go to up next significant digit
  291.  Jump INCRLOOP:         * Increment next significant digit
  292.  INCRDONE:
  293.     BegFile             * Return to beginning of text
  294.     CursorDown CursorDown  * Many cursordowns instead of displaying
  295.     CursorDown CursorDown  * RepeatCmd prompt box many times
  296.     CursorDown CursorDown
  297.     CursorDown
  298.  NEXTWORD:
  299.     MarkCharacter       * Block last word processed to delete it
  300.     WordRight           * Go to next word right
  301.  JTrue MAINLOOP:        * If no words to right, display count
  302.     UnmarkBlock
  303.     BegFile CursorRight * Go to top of 2nd column
  304.     MarkColumn          * Delete all but column 1
  305.     EndLine PageDown
  306.     DeleteBlock
  307.     JOINLOOP:           * Join column 1 into a single line
  308.       CursorUp
  309.       JFalse PROMPT:
  310.       JoinLine
  311.     Jump JOINLOOP:
  312.  PROMPT:
  313.     EndLine             * Go to end of count and display prompt
  314.     " Words... Press <Enter> to Continue"
  315.     Pause               * Wait for user to press Enter
  316.  END:
  317.     Quit CloseWindow    * Delete the NUL file and close window
  318.     DefaultWordSet      * Reset default word set characters
  319. *
  320. * 183 bytes Fri  08-23-1991  17:45:40 (JG @4)
  321.  
  322.  
  323. * (Calibrated) Test File, 41 Words with @0 and @3
  324.  
  325. * ┌────────────────────────────── WORD ─────────────────────────────────────┐
  326. * │  1 2  3                                                                 │
  327. * │                                                                         │
  328. * │ ! @ # $ % ^ & * ' ( ) + | - = \ , . / ; ' [ ] < > ? : " { }             │
  329. * │                                                                         │
  330. * │ !@#$%^&*'()+|-=\,./;'[]<>?:"{}                                          │
  331. * │                                                                         │
  332. * │  4   5   6                                                              │
  333. * │                  126__Characters 41_Words(W/@0) 41_Words(W/@3) 7 8 9 aa │
  334. * │                                                                         │
  335. * │ __ Characters                                                           │
  336. * └─────────────────────────────────────────────────────────────────────────┘
  337.  
  338.  
  339.